package com.google.code.virtualhockey.vhx.server.model

import com.google.code.virtualhockey.vhx.sds.STMetaData
import com.google.code.virtualhockey.vhx.sds.fields._
import com.google.code.virtualhockey.vhx.sds.STNamedEntity

/**
 * Represents a national union that regroups some leagues and possibly cup competitions.
 */
class NationalUnion( cpCode: String,
                     val name: String,
                     val abbreviation: String,
                     val countries: String ) extends STNamedEntity[NationalUnion] {

  setEntityName( cpCode )

  lazy val countriesAsArray: Array[String] = countries.split( "," )

  /** Private no-arg constructor for SDS. */
  private def this() = this( null, null, null, null )
}

object NationalUnionMeta extends STMetaData[NationalUnion] {
  val cls = classOf[NationalUnion]
  val kind = "NationalUnion"
  val fields = List(
    new SShortText( this, "name", true ),
    new SShortText( this, "abbreviation", true ),
    new SShortText( this, "countries", false ) )

  /**
   * Creates a new NationalUnion instance from a CSV file line.
   */
  override def fromCsv( values: List[Any] ): NationalUnion = {
    new NationalUnion( values(0).toString,
                       values(1).toString,
                       values(2).toString,
                       values(3).toString )
  }
}
